home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / antenna / yagiu112 / auto.c < prev    next >
C/C++ Source or Header  |  1995-08-25  |  3KB  |  74 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <errno.h>
  4. #ifdef sun
  5. #include <stdlib.h>
  6. #endif
  7. #include "yagi.h"
  8.  
  9. extern int errno;
  10. /* The function automatic_enhancement optimises only for the gain, by 
  11. adjusting the length of the reflector (A=-1), the driven(A=0) the 
  12. first director (A=1), second director (A=2 ) etc */
  13.  
  14. void automatic_enhancement(struct flags flag, double frequency, double **driven_data, double **parasitic_data, int driven, int parasites, struct FCOMPLEX *voltage, struct FCOMPLEX *current, struct FCOMPLEX *input_impedance, double *v, double **z,double **A, double *b, int *indx, struct element_data *coordinates)
  15. {
  16.     int i,elements,element;
  17.     double pin,E_fwd=0,H_fwd,max_gain=0.0,old_max=0.0;
  18.     elements=driven+parasites;
  19.     element=flag.Aflg-1000;
  20.     if(element > parasites-1)
  21.     {
  22.         fprintf(stderr,"You have set the option '-A%d', which will maximise gain using director number %d, but there are only %d directors\n", element,element, parasites-1);
  23.         exit(1);
  24.     }
  25.     if(element>0) /* optimise gain by adjusting a director */
  26.     {
  27.             parasitic_data[element+1][LENGTH]*=0.90;
  28.             max_gain=0.0;
  29.             old_max=0.0;
  30.             do{
  31.                 parasitic_data[element+1][LENGTH]*=1.001;
  32.                 solve_equations(frequency, driven, parasites, driven_data, parasitic_data, v, z, &pin, voltage, current, input_impedance, coordinates, A, b, indx);
  33.                 gain(90.0,0.0,pin,1.0,coordinates,current,elements,&E_fwd,&H_fwd,frequency,frequency);
  34.                 if(E_fwd>max_gain)
  35.                 {
  36.                     old_max=max_gain;
  37.                     max_gain=E_fwd;
  38.                 }
  39.             } while(E_fwd>old_max);
  40.     }
  41.     else if(element==-1) /* Optimise gain by adjeucting reflector */
  42.     {
  43.         parasitic_data[1][LENGTH]*=0.90;
  44.         max_gain=0.0;
  45.         old_max=0.0;
  46.         do{
  47.             parasitic_data[1][LENGTH]*=1.001;
  48.             solve_equations(frequency, driven, parasites, driven_data, parasitic_data, v, z, &pin, voltage, current, input_impedance, coordinates, A, b, indx);
  49.             gain(90.0,0.0,pin,1.0,coordinates,current,elements,&E_fwd,&H_fwd,frequency,frequency);
  50.             if(E_fwd>max_gain)
  51.             {
  52.                 old_max=max_gain;
  53.                 max_gain=E_fwd;
  54.             }
  55.         } while(E_fwd>old_max);
  56.     } 
  57.     else if(element==0) /* Optimise gain by adjeucting driven-element */
  58.     {
  59.         driven_data[1][LENGTH]*=0.90;
  60.         max_gain=0.0;
  61.         old_max=0.0;
  62.         do{
  63.             driven_data[1][LENGTH]*=1.001;
  64.             solve_equations(frequency, driven, parasites, driven_data, parasitic_data, v, z, &pin, voltage, current, input_impedance, coordinates, A, b, indx);
  65.             gain(90.0,0.0,pin,1.0,coordinates,current,elements,&E_fwd,&H_fwd,frequency,frequency);
  66.             if(E_fwd>max_gain)
  67.             {
  68.                 old_max=max_gain;
  69.                 max_gain=E_fwd;
  70.             }
  71.         } while(E_fwd>old_max);
  72.     } 
  73. }
  74.